<script setup>
import { computed } from 'vue'
import moment from 'moment'
import './index.scss'
const props = defineProps({
  policyInformation: Object,
  modelValue: {
    type: Object
  },
})
const emit = defineEmits(['update:modelValue']);
const formData = computed({
  get: () => {
    return props.modelValue
  },
  set: value => {
    emit('update:modelValue', value)
  }
})
const defaultTime = [
  new Date(2000, 1, 1, 0, 0, 0),
  new Date(2000, 2, 1, 23, 59, 59),
]

const getNeverTime = (item) => {
  props.policyInformation.clearValidate(item);
  const today = moment(moment().startOf('day')).format('YYYY-MM-DD HH:mm:ss');
  const begin = moment(today).subtract(1, "years").format('YYYY-MM-DD HH:mm:ss');
  const end = moment(today).add(10, "years").endOf('day').format('YYYY-MM-DD HH:mm:ss');
  formData.value[item] = [begin, end];
};
</script>
<template>
  <el-form-item label="策略名称：" prop="strategy_name">
    <el-input v-model="formData.strategy_name" class="input" placeholder="策略名称" />
  </el-form-item>
  <el-form-item label="策略优先级：">
    <VXSelect v-model="formData.priority" class="input mr-[8px]" placeholder="数字越大优先级越高" dictionary="order_strategy_order_priority" />
    数字越大优先级越高！
  </el-form-item>
  <el-form-item label="策略说明：">
    <el-input v-model="formData.strategy_description" class="input" placeholder="策略说明" />
  </el-form-item>
  <el-form-item label="策略有效时间：" prop="strategy_time" class="picker-btn-box">
    <el-date-picker v-model="formData.strategy_time" type="datetimerange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" style="max-width: 400px" value-format="YYYY-MM-DD HH:mm:ss" :default-time="defaultTime" />
    <span class="picker-btn" @click="() => getNeverTime('strategy_time')">永久有效</span>
  </el-form-item>

  <el-form-item label="订单支付时间：" prop="order_pay_time" class="picker-btn-box">
    <el-date-picker v-model="formData.order_pay_time" type="datetimerange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" style="max-width: 400px" value-format="YYYY-MM-DD HH:mm:ss" :default-time="defaultTime" />
    <span class="picker-btn" @click="() => getNeverTime('order_pay_time')">永久有效</span>
  </el-form-item>
</template>
<style scoped lang="scss">
</style>